﻿using System;
using System.ServiceProcess;
using Ninject;
using Synology.DS.Common;
using Synology.DS.Interface.Abstract;
using Synology.DS.IoC;

namespace Synology.DS.Service
{
    class Program : IInstanceResolver
    {
        private static StandardKernel _kernel;

        static void Main(string[] args)
        {
            Log.Initialize();

            _kernel = new StandardKernel();
            _kernel.Load(typeof(IocAssemblyMarker).Assembly);
            _kernel.Bind<IInstanceResolver>().To<Program>();

            if (Environment.UserInteractive)
            {
                var server = _kernel.Get<IProcessingServer>();
                server.Start();

                Console.WriteLine("Press any button to stop server...");
                Console.ReadKey();
                server.Stop();    
            }
            else
            {
                ProcessingService service = _kernel.Get<ProcessingService>();
                ServiceBase.Run(service);   
            }
        }

        public T Resolve<T>()
        {
            return _kernel.Get<T>();
        }
    }
}
